package com.hk.elseservice.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类
 */
@Configuration
public class RabbitConfig {

//    @Resource(name = "empQueue")
//    private Queue queue;

//    @Autowired
//    @Qualifier("empQueue")
//    private Queue queue;

//    @Autowired
//    private Queue leaderQueue;

    /*@Bean
    public Queue empQueue() {
        return new Queue("EmpQueue",true);
    }
    @Bean
    public Queue leaderQueue() {
        return new Queue("LeaderQueue",true);
    }

    @Bean
    DirectExchange userDirectExchange() {
        return new DirectExchange("userDirectExchange",true,false);
    }

    @Bean
    FanoutExchange userFanoutExchange() {
        return new FanoutExchange("userFanoutExchange",true,false);
    }

    @Bean
    TopicExchange userTopicExchange() {
        return new TopicExchange("userTopicExchange",true,false);
    }

    @Bean
    Binding empQueueToUserDirect() {
        return BindingBuilder.bind(empQueue()).to(userDirectExchange()).with("emp.queue");
    }
    @Bean
    Binding leaderQueueToUserDirect() {
        return BindingBuilder.bind(leaderQueue()).to(userDirectExchange()).with("leader.queue");
    }

    @Bean
    Binding empQueueToUserFanout() {
        return BindingBuilder.bind(empQueue()).to(userFanoutExchange());
    }
    @Bean
    Binding leaderQueueToUserFanout() {
        return BindingBuilder.bind(leaderQueue()).to(userFanoutExchange());
    }

    @Bean
    Binding empQueueToUserTopic() {
        return BindingBuilder.bind(empQueue()).to(userTopicExchange()).with("a.email");
    }

    @Bean
    Binding leaderQueueToUserTopic() {
        return BindingBuilder.bind(leaderQueue()).to(userTopicExchange()).with("a.#");
    }*/

    /**
     * 自定义交换机和队列
     */

//    邮箱 消息队列
    @Bean
    public Queue emailQueue() {
        return new Queue("EmailQueue",true);
    }

//  邮箱 交换机
    @Bean
    TopicExchange emailTopicExchange() {
        return new TopicExchange("emailTopicExchange",true,false);
    }

//    通过a.email将交换机和队列进行绑定
    @Bean
    Binding empQueueToUserTopic() {
        return BindingBuilder.bind(emailQueue()).to(emailTopicExchange()).with("a.email");
    }




}